<?php
namespace Home\Controller;
use Think\Controller;
use Think\Controller\JsonRpcController;
class IndexController extends Controller {
    public function index(){
    	$friend = D('friend')->select();
    	$lunbo = D('arts')->where("author='lunbo'")->cache(true)->select();
    	$ads01 = D('ads')->where("mark='index01'")->cache(true)->find();
    	$ads02 = D('ads')->where("mark='index02'")->cache(true)->find();
        //分页
        $num = 5;
        $count = D('arts')->where("author!='lunbo'")->cache(true)->count();
        $pager = new \Org\Util\BootStrapPage($count,$num);
    	$arts = D('arts')->where("author!='lunbo'")->order('aid desc')->limit($pager->firstRow.','.$pager->listRows)->select();
        $hot = D('arts')->where("author!='lunbo'")->field('aid,title,author,clicknum')->order('clicknum desc')->limit(0,5)->cache(true)->select();
        $new = D('arts')->where("author!='lunbo'")->field('aid,title,author,clicknum')->order('aid desc')->limit(0,5)->cache(true,60)->select();
        $page = $pager->show();
    	$this->assign('friend',$friend);
    	$this->assign('lunbo',$lunbo);
    	$this->assign('ads01',$ads01);
    	$this->assign('ads02',$ads02);
    	$this->assign('arts',$arts);
        //分页
        $this->assign('page',$page);
        //最热文章
        $this->assign('hot',$hot);
        $this->assign('new',$new);
        $this->display();
    }
    //站内搜索
    public function search(){
        $key = '%'.I('get.key').'%';
        $where['title|content'] = array('like',$key); 
        $res = D('arts')->where($where)->field('aid,title,img_path,clicknum')->order('aid desc')->limit('0,10')->select();
        $this->assign('key',$res);
        $this->display();
    }
}